home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / PROGTOOL / FLI106C.ZIP;1 / WINUSE.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-12  |  15.6 KB  |  628 lines

  1. //
  2. // The Fusion Library Interface for DOS
  3. // Version 1.06c
  4. // Copyright (C) 1990, 1991, 1992
  5. // Software Dimensions
  6. //
  7. // FusionWindow
  8. //
  9.  
  10. #include "fliwin.h"
  11.  
  12. #ifdef __BCPLUSPLUS__
  13. #pragma hdrstop
  14. #endif
  15.  
  16. #include <alloc.h>
  17. #include <bios.h>
  18.  
  19. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  20. //
  21. // EngageFusion()
  22. //
  23. // Enganges the Fusion Windows system
  24. //
  25. //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  26.  
  27. int FusionWindow::EngageFusion()
  28. {
  29.   register int i;
  30.  
  31.   BlazeClass Blaze;
  32.  
  33.   long VirtualLapseTime=biostime(0,0);
  34.  
  35.   if (!NumberOfMenus)
  36.     return NoAvailableMenus;
  37.  
  38.   if (CurrentLevel)
  39.   {
  40.     free(SubMenuTrack);
  41.     CurrentLevel=0;
  42.     SubMenuTrack=0;
  43.   }
  44.  
  45.   Blaze.FreshWorkSpace();
  46.  
  47.   SetMenuBar(0,0,Blaze.WhatWidth());
  48.  
  49.   if (NumberOfWindows)
  50.     RefreshWindows();
  51.  
  52.   int Event;
  53.   MouseInControl=1;
  54.  
  55.   HelpId=DefaultHelp;
  56.  
  57.   EventHandler(EngageEvent);
  58.  
  59.   for (;;)
  60.   {
  61.  
  62. TopLoop:
  63.  
  64.     if (!CurrentLevel &&
  65.       (!NumberOfWindows ||
  66.       (NumberOfWindows && !Windows[0]->CurrentLevel)))
  67.     {
  68.       if (!NumberOfWindows)
  69.         RefreshPromptLine();
  70.       else
  71.       {
  72.         if (!Windows[0]->RefreshPromptLine())
  73.           RefreshPromptLine();
  74.       }
  75.       HelpId=DefaultHelp;
  76.       if (NumberOfWindows)
  77.         Windows[0]->Cursor();
  78.     }
  79.  
  80.     //--------------------------------------------------------------
  81.     //
  82.     // Get event, if none - process virtual windows
  83.     //
  84.     //--------------------------------------------------------------
  85.  
  86.     if (!CheckVirtuals())
  87.       Event=GetEvent();
  88.     else
  89.     {
  90.       while(!(Event=GetEvent(1)))
  91.       {
  92.         if (biostime(0,0)>(VirtualLapseTime+VirtualizeInterval))
  93.         {
  94.           VirtualizeFresh();
  95.           VirtualLapseTime=biostime(0,0);
  96.         }
  97.       }
  98.     }
  99.  
  100.     //--------------------------------------------------------------
  101.     //
  102.     // A help event occured
  103.     //
  104.     //--------------------------------------------------------------
  105.  
  106. ComeBack:
  107.  
  108.     if (Event==HelpEvent)
  109.     {
  110.       if (CurrentLevel)
  111.         MouseInControl=0;
  112.       else if (NumberOfWindows && Windows[0]->CurrentLevel)
  113.         Windows[0]->MouseInControl=0;
  114.       continue;
  115.     }
  116.  
  117.     //--------------------------------------------------------------
  118.     //
  119.     // Check for a shift event
  120.     //
  121.     //--------------------------------------------------------------
  122.  
  123.     if (Event==ShiftEvent)
  124.     {
  125.       if (!CurrentLevel &&
  126.         (!NumberOfWindows ||
  127.         (NumberOfWindows && !Windows[0]->CurrentLevel)))
  128.       {
  129.         if (!NumberOfWindows)
  130.           RefreshPromptLine();
  131.         else
  132.         {
  133.           if (!Windows[0]->RefreshPromptLine())
  134.             RefreshPromptLine();
  135.         }
  136.         HelpId=DefaultHelp;
  137.       }
  138.       continue;
  139.     }
  140.  
  141.     //--------------------------------------------------------------
  142.     //
  143.     // Check the global menus
  144.     //
  145.     //--------------------------------------------------------------
  146.  
  147.     if (!NumberOfWindows ||
  148.        (NumberOfWindows &&
  149.        (!Windows[0]->CurrentLevel ||
  150.         (Windows[0]->CurrentLevel && Event!=MousedEvent))))
  151.     {
  152.       int Save;
  153.       switch(Save=Manager(Event,0,NumberOfWindows,*Windows[0],*this))
  154.       {
  155.         case NothingEvent:
  156.           RefreshMenus();
  157.           break;
  158.  
  159.         case MenuEvent:
  160.           RefreshMenus();
  161.           if (CurrentLevel && Event!=MousedEvent)
  162.             break;
  163.           goto TopLoop;
  164.  
  165.         case MenusRemoved:
  166.           RefreshMenus();
  167.           RefreshPromptLine();
  168.           goto ComeBack;
  169.  
  170.         default:
  171.           MouseInControl=0;
  172.           RefreshMenus();
  173.           switch(EventHandler(Save))
  174.           {
  175.             case CompleteEvent:
  176.               RefreshMenus();
  177.               continue;
  178.  
  179.             case StopEvent:
  180.               RefreshMenus();
  181.               EventHandler(DisEngageEvent);
  182.               return StopEvent;
  183.  
  184.             case RefreshEvent:
  185.               RefreshMenus();
  186.               RefreshWindows();
  187.               continue;
  188.  
  189.             default:
  190.               if (NumberOfWindows)
  191.               {
  192.                 switch(Windows[0]->EventHandler(Save))
  193.                 {
  194.                   case CompleteEvent:
  195.                     RefreshMenus();
  196.                     continue;
  197.  
  198.                   case StopEvent:
  199.                     EventHandler(DisEngageEvent);
  200.                     return StopEvent;
  201.  
  202.                   case RefreshEvent:
  203.                     RefreshMenus();
  204.                     RefreshWindows();
  205.                     continue;
  206.  
  207.                   default:
  208.                     RefreshMenus();
  209.                     goto TopLoop;
  210.                 }
  211.               }
  212.               goto TopLoop;
  213.           }
  214.       }
  215.     }
  216.  
  217.     //--------------------------------------------------------------
  218.     //
  219.     // Check the window menus
  220.     //
  221.     //--------------------------------------------------------------
  222.  
  223.     if (NumberOfWindows && Windows[0]->NumberOfMenus)
  224.     {
  225.       if (CurrentLevel && Event==MousedEvent)
  226.         goto TopLoop;
  227.  
  228.       int Save;
  229.       switch(Save=Windows[0]->Manager(Event,1,NumberOfWindows,*Windows[0],*this))
  230.       {
  231.         case NothingEvent:
  232.           Windows[0]->RefreshMenus();
  233.           break;
  234.  
  235.         case MenuEvent:
  236.           Windows[0]->RefreshMenus();
  237.           HelpId=Windows[0]->HelpId;
  238.           goto TopLoop;
  239.  
  240.         case MenusRemoved:
  241.           Windows[0]->RefreshMenus();
  242.           RefreshPromptLine();
  243.           goto ComeBack;
  244.  
  245.         default:
  246.           Windows[0]->MouseInControl=0;
  247.           Windows[0]->RefreshMenus();
  248.           switch(Windows[0]->EventHandler(Save))
  249.           {
  250.             case CompleteEvent:
  251.               Windows[0]->RefreshMenus();
  252.               continue;
  253.  
  254.             case StopEvent:
  255.               EventHandler(DisEngageEvent);
  256.               return StopEvent;
  257.  
  258.             case RefreshEvent:
  259.               Windows[0]->RefreshMenus();
  260.               RefreshWindows();
  261.               continue;
  262.  
  263.             case CloseEvent:
  264.               CloseWindow();
  265.               continue;
  266.  
  267.             default:
  268.               goto TopLoop;
  269.           }
  270.       }
  271.     }
  272.  
  273.     //--------------------------------------------------------------
  274.     //
  275.     // Check the prompt line
  276.     //
  277.     //--------------------------------------------------------------
  278.  
  279.     if (Event==MousedEvent &&
  280.        !CurrentLevel &&
  281.        (!NumberOfWindows ||
  282.        (NumberOfWindows && !Windows[0]->CurrentLevel)))
  283.     {
  284.       int Save;
  285.  
  286.       if (!NumberOfWindows)
  287.         Save=CheckPromptLine();
  288.       else
  289.       {
  290.         Save=Windows[0]->CheckPromptLine();
  291.         if (Save && Save!=1)
  292.           Save=EventHandler(Save);
  293.         else if (!Save)
  294.           Save=CheckPromptLine();
  295.       }
  296.  
  297.       switch(Save)
  298.       {
  299.         case 0:
  300.         case 1:
  301.           break;
  302.  
  303.         case CompleteEvent:
  304.           goto TopLoop;
  305.  
  306.         case StopEvent:
  307.           EventHandler(DisEngageEvent);
  308.           return StopEvent;
  309.  
  310.         case RefreshEvent:
  311.           RefreshWindows();
  312.           goto TopLoop;
  313.  
  314.         default:
  315.           if (NumberOfWindows)
  316.           {
  317.             switch(Windows[0]->EventHandler(Save))
  318.             {
  319.               case CompleteEvent:
  320.                 continue;
  321.  
  322.               case StopEvent:
  323.                 EventHandler(DisEngageEvent);
  324.                 return StopEvent;
  325.  
  326.               case RefreshEvent:
  327.                 RefreshWindows();
  328.                 continue;
  329.  
  330.               default:
  331.                 goto TopLoop;
  332.             }
  333.           }
  334.       }
  335.     }
  336.  
  337.     //--------------------------------------------------------------
  338.     //
  339.     // Check to see if a size corner or move handle was grabbed
  340.     //
  341.     //--------------------------------------------------------------
  342.  
  343.     if (Event==MousedEvent && MouseEvent&MouseLeftButtonPress &&
  344.        !CurrentLevel &&
  345.        (!NumberOfWindows ||
  346.        (NumberOfWindows && !Windows[0]->CurrentLevel)))
  347.     {
  348.       if (CheckMoveOrSize())
  349.         continue;
  350.     }
  351.  
  352.     //--------------------------------------------------------------
  353.     //
  354.     // Check to see if a scroll bar was grabbed or scroll arrow was
  355.     // depressed
  356.     //
  357.     //--------------------------------------------------------------
  358.  
  359.     if (Event==MousedEvent &&
  360.        (MouseEvent&MouseLeftButtonPress || MouseEvent&MouseHeldDown || MouseEvent&MouseLeftButtonRelease) &&
  361.         !CurrentLevel &&
  362.        (!NumberOfWindows ||
  363.        (NumberOfWindows && !Windows[0]->CurrentLevel)))
  364.     {
  365.       if (!CurrentLevel &&
  366.         (NumberOfWindows && !Windows[0]->CurrentLevel))
  367.       {
  368.         if (Windows[0]->CheckScrollBar())
  369.           goto TopLoop;
  370.       }
  371.     }
  372.  
  373.     //--------------------------------------------------------------
  374.     //
  375.     // Check to see where and how to respond to a button release
  376.     //
  377.     //--------------------------------------------------------------
  378.  
  379.     int BackSaveEvent;
  380.  
  381.     if (Event==MousedEvent &&
  382.         (MouseEvent&MouseLeftButtonRelease || MouseEvent&MouseLeftButtonPress) &&
  383.         !CurrentLevel &&
  384.        (!NumberOfWindows ||
  385.        (NumberOfWindows && !Windows[0]->CurrentLevel)))
  386.     {
  387.       WindowElement &Window=*Windows[0];
  388.  
  389.       if ((MouseHorizontal>=Window.X+Window.Width
  390.         || MouseHorizontal<Window.X
  391.         || MouseVertical>=Window.Y+Window.Height
  392.         || MouseVertical<Window.Y)
  393.         && NumberOfWindows>1)
  394.       {
  395.         for (i=1;i<NumberOfWindows;i++)
  396.         {
  397.           if (MouseHorizontal<Windows[i]->X+Windows[i]->Width
  398.             && MouseHorizontal>=Windows[i]->X
  399.             && MouseVertical<Windows[i]->Y+Windows[i]->Height
  400.             && MouseVertical>=Windows[i]->Y)
  401.           {
  402.             CallWindow(i);
  403.             BackSaveEvent=Event;
  404.             Event=SwitchEvent;
  405.             goto RawEvent;
  406.           }
  407.         }
  408.       }
  409.  
  410.       //--------------------------------------------------------------
  411.       //
  412.       // Check to see if the zoom icon was clicked and zoom or unzoom
  413.       // the window
  414.       //
  415.       //--------------------------------------------------------------
  416.  
  417.       if (Event==MousedEvent && MouseEvent&MouseLeftButtonRelease &&
  418.         !CurrentLevel &&
  419.        (!NumberOfWindows ||
  420.        (NumberOfWindows && !Windows[0]->CurrentLevel)))
  421.       {
  422.         if (Window.ZoomIcon
  423.           && MouseHorizontal<Window.X+Window.Width-1
  424.           && MouseHorizontal>=Window.X+Window.Width-3
  425.           && MouseVertical==Window.Y)
  426.         {
  427.           ZoomWindow();
  428.           goto TopLoop;
  429.         }
  430.  
  431.         if (Window.CloseIcon
  432.           && MouseHorizontal<=Window.X+3
  433.           && MouseHorizontal>Window.X
  434.           && MouseVertical==Window.Y)
  435.         {
  436.           CloseWindow();
  437.           Event=CloseEvent;
  438.           goto RawEvent;
  439.         }
  440.       }
  441.     }
  442.  
  443.     //--------------------------------------------------------------
  444.     //
  445.     // Check to see if within and a window and validate the event
  446.     //
  447.     //--------------------------------------------------------------
  448.  
  449.     if (Event==MousedEvent &&
  450.        !CurrentLevel &&
  451.       (!NumberOfWindows ||
  452.       (NumberOfWindows && !Windows[0]->CurrentLevel)))
  453.     {
  454.       if (NumberOfWindows)
  455.       {
  456.         WindowElement &Window=*Windows[0];
  457.  
  458.         if (MouseHorizontal<Window.X+Window.Width-1
  459.           && MouseHorizontal>Window.X
  460.           && MouseVertical<Window.Y+Window.Height-1
  461.           && MouseVertical>Window.Y+((Window.NumberOfMenus)?1:0))
  462.         {
  463.           MouseHorizontal-=(Window.X+1);
  464.           MouseVertical-=(Window.Y+1);
  465.  
  466.           if (Window.NumberOfMenus)
  467.             MouseVertical--;
  468.  
  469.           switch(Windows[0]->EventHandler(ValidatedMousedEvent))
  470.           {
  471.             case CompleteEvent:
  472.               continue;
  473.  
  474.             case StopEvent:
  475.               EventHandler(DisEngageEvent);
  476.               return StopEvent;
  477.  
  478.             case RefreshEvent:
  479.               RefreshWindows();
  480.               continue;
  481.           }
  482.         }
  483.       }
  484.     }
  485.  
  486.     //------------------------------------------------------------
  487.     //
  488.     // Check to see if one of the windows was called up using a
  489.     // quick window key (Alt+1 - Alt+9)
  490.     //
  491.     // Starting with FLI 1.06, the Alt+0 combination has been
  492.     // left open for the programmer to define.
  493.     //
  494.     //------------------------------------------------------------
  495.  
  496.     if (Event!=MousedEvent && NumberOfWindows && Event>=kbAlt1 && Event<=kbAlt9 &&
  497.         !CurrentLevel &&
  498.        (!NumberOfWindows ||
  499.        (NumberOfWindows && !Windows[0]->CurrentLevel)))
  500.     {
  501.       Event=(Event-kbAlt1)+1;
  502.       for (i=0;i<NumberOfWindows;i++)
  503.       {
  504.         if (Event==Windows[i]->WindowNumber)
  505.         {
  506.           CallWindow(i);
  507.           Event=SwitchEvent;
  508.           goto RawEvent;
  509.         }
  510.       }
  511.       goto TopLoop;
  512.     }
  513.  
  514.     //------------------------------------------------------------
  515.     //
  516.     // Pass event along to the assessment queue for processing.
  517.     //
  518.     //------------------------------------------------------------
  519.  
  520.     if (!CurrentLevel &&
  521.        (!NumberOfWindows ||
  522.        (NumberOfWindows && !Windows[0]->CurrentLevel)))
  523.     {
  524.       int Save;
  525.  
  526.       if (NumberOfWindows)
  527.       {
  528.         if (!Windows[0]->CheckEvent(Event) && !CheckEvent(Event))
  529.           goto RawEvent;
  530.         if (!(Save=Windows[0]->CheckEvent(Event)))
  531.           Save=CheckEvent(Event);
  532.       }
  533.       else if (!(Save=CheckEvent(Event),Save))
  534.         goto RawEvent;
  535.  
  536.       switch(EventHandler(Save))
  537.       {
  538.         case CompleteEvent:
  539.           continue;
  540.  
  541.         case StopEvent:
  542.           EventHandler(DisEngageEvent);
  543.           return StopEvent;
  544.  
  545.         case RefreshEvent:
  546.           RefreshWindows();
  547.           continue;
  548.  
  549.         default:
  550.           if (NumberOfWindows)
  551.           {
  552.             switch(Windows[0]->EventHandler(Save))
  553.             {
  554.               case CompleteEvent:
  555.                 continue;
  556.  
  557.               case StopEvent:
  558.                 EventHandler(DisEngageEvent);
  559.                 return StopEvent;
  560.  
  561.               case RefreshEvent:
  562.                 RefreshWindows();
  563.                 continue;
  564.             }
  565.           }
  566.       }
  567.  
  568.       //------------------------------------------------------------
  569.       //
  570.       // Just pass the raw event though to the global
  571.       // event handler and see what happens.
  572.       //
  573.       //------------------------------------------------------------
  574.  
  575. RawEvent:
  576.  
  577.       switch(EventHandler(Event))
  578.       {
  579.         case CompleteEvent:
  580.           continue;
  581.  
  582.         case StopEvent:
  583.           EventHandler(DisEngageEvent);
  584.           return StopEvent;
  585.  
  586.         case RefreshEvent:
  587.           RefreshWindows();
  588.           continue;
  589.       }
  590.  
  591.       if (Event==CloseEvent)
  592.         continue;
  593.  
  594.       if (Event==SwitchEvent)
  595.       {
  596.         Event=BackSaveEvent;
  597.         goto ComeBack;
  598.       }
  599.  
  600.       //------------------------------------------------------------
  601.       //
  602.       // Pass event along to the current window and see if it is a
  603.       // key that the window can use.  If it cannot be used at this
  604.       // phase, it is thrown out
  605.       //
  606.       //------------------------------------------------------------
  607.  
  608.       if (NumberOfWindows)
  609.       {
  610.         switch(Windows[0]->EventHandler(Event))
  611.         {
  612.           case CompleteEvent:
  613.             continue;
  614.  
  615.           case StopEvent:
  616.             EventHandler(DisEngageEvent);
  617.             return StopEvent;
  618.  
  619.           case RefreshEvent:
  620.             RefreshWindows();
  621.             continue;
  622.         }
  623.       }
  624.     }
  625.   }
  626. }
  627.  
  628.